class TreeNode:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

def build_binary_tree():
    data = input("请输入一组数据，以空格分隔：").split()
    root = TreeNode(data[0])
    stack = [root]
    i = 1

    while i < len(data):
        current_node = stack.pop()

        # 左子树
        if data[i] != '#':
            current_node.left = TreeNode(data[i])
            stack.append(current_node.left)
        i += 1

        # 右子树
        if i < len(data) and data[i] != '#':
            current_node.right = TreeNode(data[i])
            stack.append(current_node.right)
        i += 1

    return root

def preorder_traversal(node):
    if node:
        print(node.data, end=" ")
        preorder_traversal(node.left)
        preorder_traversal(node.right)

def inorder_traversal(node):
    if node:
        inorder_traversal(node.left)
        print(node.data, end=" ")
        inorder_traversal(node.right)

def postorder_traversal(node):
    if node:
        postorder_traversal(node.left)
        postorder_traversal(node.right)
        print(node.data, end=" ")

# 主程序
if __name__ == "__main__":
    root = build_binary_tree()

    print("先序遍历结果：", end=" ")
    preorder_traversal(root)
    print()

    print("中序遍历结果：", end=" ")
    inorder_traversal(root)
    print()

    print("后序遍历结果：", end=" ")
    postorder_traversal(root)
    print()
class TreeNode:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

def count_leaves(node):
    if node is None:
        return 0
    elif node.left is None and node.right is None:
        # 当前节点是叶子节点
        return 1
    else:
        # 递归计算左右子树的叶子节点数
        left_leaves = count_leaves(node.left)
        right_leaves = count_leaves(node.right)

        # 返回左右子树的叶子节点数之和
        return left_leaves + right_leaves

# 主程序
if __name__ == "__main__":

    root = TreeNode(1)
    root.left = TreeNode(2)
    root.right = TreeNode(3)
    root.left.left = TreeNode(4)
    root.left.right = TreeNode(5)

    # 计算叶子节点数
    leaves_count = count_leaves(root)
    print("二叉树的叶子节点数为:", leaves_count)
class TreeNode:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

def max_depth(root):
    if root is None:
        return 0
    else:
        left_depth = max_depth(root.left)
        right_depth = max_depth(root.right)

        # 返回左右子树中较大深度的值加上根节点
        return max(left_depth, right_depth) + 1

# 主程序
if __name__ == "__main__":

    root = TreeNode(1)
    root.left = TreeNode(2)
    root.right = TreeNode(3)
    root.left.left = TreeNode(4)
    root.left.right = TreeNode(5)

    # 计算深度
    depth = max_depth(root)
    print("二叉树的深度为:", depth)